package com.dyh.controller;


import com.dyh.po.farmer;
import com.dyh.service.farmerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.List;

@Controller
public class farmerController {
    @Autowired
    private farmerService farmerservice;

    @RequestMapping(value = "/farmerList")
    public String findAllFarmer(HttpServletRequest request, Model model){
        try {
            request.setCharacterEncoding("UTF-8");
        }catch (UnsupportedEncodingException e){
            e.printStackTrace();
        }
        String keyword = request.getParameter("keyword");
        System.out.println("keyword="+keyword);
        List<farmer> farmerList = farmerservice.findAllFarmer(keyword);
        model.addAttribute("farmerList",farmerList);
        return "farmer/farmerList";
    }

    @RequestMapping(value = "/farmerInf")
    public String farmerInf(@RequestParam("familyId") String familyId, Model model){
        System.out.println(familyId);
        farmer farmer = farmerservice.findFarmerById(familyId);
        model.addAttribute("farmer",farmer);
        return "farmer/farmerInf";
    }
}
